package com.timetable;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.easylib.base.BaseActivity;
import com.guyj.CommonAdapter;
import com.guyj.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MemorandumActivity extends BaseActivity {

    @Bind(R.id.tv_class)
    TextView tvClass;
    @Bind(R.id.tv_department)
    TextView tvDepartment;
    @Bind(R.id.tv_add)
    TextView tvAdd;
    @Bind(R.id.recycler)
    RecyclerView recycler;
    @Bind(R.id.activity_memorandum)
    LinearLayout activityMemorandum;

    LinearLayoutManager llm;
    List<TableBean> list1,list2;
    CommonAdapter adapter;
    int chooseType=0;

    @Override
    public int getContentViewId() {
        return R.layout.activity_memorandum;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {

    }

    @Override
    protected void initVariable() {
        llm=new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false);
        list1=new ArrayList<>();
        list2=new ArrayList<>();
        list1.add(new TableBean("三年二班","三年二班周杰伦 马上到训导处来"));
        list1.add(new TableBean("二年三班","二年三班周杰 马上到训导处来"));
        list2.add(new TableBean("校长室","全体师生注意，今天我们要表扬一位新同学，他为校争光，我们要向他看齐。"));
        list2.add(new TableBean("广播室","全体师生注意，今天我们又要表扬一位新同学，他为校争光，我们要向他看齐。"));
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {
        recycler.setLayoutManager(llm);
        recycler.addItemDecoration(new DividerItemDecoration(mContext,DividerItemDecoration.VERTICAL));
        recycler.setAdapter(adapter=new CommonAdapter<TableBean>(mContext,R.layout.item_table,list1) {
            @Override
            protected void convert(ViewHolder viewHolder, TableBean o, int i) {
                viewHolder.setText(R.id.tv_title,o.getTitle());
                viewHolder.setText(R.id.tv_content,o.getContent());
            }
        });
    }

    private String title,content;
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==0x01&&resultCode==RESULT_OK){
            title= data.getStringExtra("title");
            content=data.getStringExtra("content");
            if (chooseType==0){
                list1.add(new TableBean(title,content));
                adapter.setDatas(list1);
            }else {
                list2.add(new TableBean(title,content));
                adapter.setDatas(list2);
            }
        }
    }

    @OnClick({R.id.tv_class, R.id.tv_department, R.id.tv_add})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_class:
                adapter.setDatas(list1);
                tvDepartment.setTextColor(Color.parseColor("#999999"));
                tvClass.setTextColor(Color.parseColor("#111111"));
                chooseType=0;
                break;
            case R.id.tv_department:
                adapter.setDatas(list2);
                tvClass.setTextColor(Color.parseColor("#999999"));
                tvDepartment.setTextColor(Color.parseColor("#111111"));
                chooseType=1;
                break;
            case R.id.tv_add:
                Intent intent = new Intent(mContext,InputActivity.class);
                intent.putExtra("type",chooseType);
                startActivityForResult(intent,0x01);
                break;
        }
    }
}
